﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PSTS.Models;
using PSTS.UI.ViewModels;

namespace PSTS.UI.Views.Pages
{
    /// <summary>
    /// Interaction logic for QuestionPage.xaml
    /// </summary>
    public partial class QuestionPage : Page
    {
        public QuestionPage()
        {
            InitializeComponent();
        }

        public QuestionPage(Question question)
        {
            InitializeComponent();
            _questionTextBox.Text = question.Text;
            Answers = new List<RadioButton>();
            for (var i = 0; i < question.Answers.Count; i++)
            {
                var item = new RadioButton {Margin = new Thickness(10, 10, 10, 10), Content = question.Answers[i]};
                _answers.Children.Add(item);
                Answers.Add(item);
            }

        }

        public List<RadioButton> Answers{ get; set; }

        public bool IsConfirmed { get; private set; }


        public void Confirm()
        {
            if (!IsConfirmed)
            {
                IsConfirmed = true;
                foreach (var radioButton in Answers)
                {
                    radioButton.IsEnabled = false;
                }
            }
        }

        public int Answer()
        {
            int res = -1;
            for(int i =0; i < Answers.Count; i++)
            {
                if (Answers[i].IsChecked == true)
                {
                    res = i;
                    break;
                }
            }
            return res;
        }
    }
}
